CSharpTest.Net
Combine(Byte[]) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > Hash Class > Combine Method : Combine(Byte[]) Method

bytes

Glossary Item Box

Combines the bytes provided by first computing a like sized hash of those bytes and then combining the two equal hash values with the same hash algorithm.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Combine( _
   ByVal bytes() As Byte _
) As Hash
C# 
public Hash Combine( 
   byte[] bytes
)

Parameters

bytes

Example

Library/Library.Test/TestHash.cs

C#Copy Code
Random r = new Random();
byte[] a = new byte[10], b = new byte[32];
r.NextBytes(a);
r.NextBytes(b);

Hash h1 = Hash.SHA256(a);
Hash h3 = h1.Combine(b);

Assert.AreEqual(h3.ToString(), Hash.SHA256(
    new CombinedStream(
        new MemoryStream(h1.ToArray()),
        new MemoryStream(Hash.SHA256(b).ToArray())//bytes combined are hashed first
        )).ToString());
VB.NETCopy Code
Dim r As New Random()
Dim a As Byte() = New Byte(10) {}, b As Byte() = New Byte(32) {}
r.NextBytes(a)
r.NextBytes(b)

Dim h1 As Hash = Hash.SHA256(a)
Dim h3 As Hash = h1.Combine(b)

'bytes combined are hashed first
Assert.AreEqual(h3.ToString(), Hash.SHA256(New CombinedStream(New MemoryStream(h1.ToArray()), New MemoryStream(Hash.SHA256(b).ToArray()))).ToString())

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys